﻿using RemoteData.model;
using System;
using System.Linq;
using System.Windows.Data;
using System.Windows.Media;

namespace RemoteData.common.converter
{
    public class cellForegroundConvert : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values == null || values.Length != 3)
                throw new ArgumentException("parameter counts doesn't match");

            UpdateStatus[] statusList = values[0] as UpdateStatus[];

            string[] colors = ((string)values[1]).Split(',');
            if (colors.Count() != 2)
            {
                throw new ArgumentException("color parameters count doesn't match");
            }
            string warnTextColor = colors[0]; //#FFFFFF
            if (warnTextColor == null)
            {
                warnTextColor = "#000000";
            }

            string textColor = colors[1]; //#000000;




            int columnNo = (int)values[2];
            int channelIndex = columnNo - 1;//减去前面一个通道号列



            if (channelIndex < statusList.Length && channelIndex >= 0)
            {
                int val = statusList[channelIndex].status;
                if (statusList[channelIndex].updateFlag && statusList[channelIndex].status == 1)
                {
                    textColor = warnTextColor;
                }
            }

            return new SolidColorBrush((Color)ColorConverter.ConvertFromString(textColor));
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
